package com.mallcai.bigdata.ladon.service.report.impl.handler;

import com.mallcai.bigdata.ladon.dpl.entity.report.QueryField;
import com.mallcai.bigdata.ladon.dpl.entity.report.Report;
import com.mallcai.bigdata.ladon.service.report.IReportService;
import com.mallcai.bigdata.ladon.service.report.impl.ReportQueryConstants;
import com.mallcai.bigdata.ladon.service.report.impl.ReportQueryContext;
import com.mallcai.bigdata.ladon.utils.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-22 09:48
 */
@Order(3000)
@Component
public class SetQueryFieldHandler extends AbstractReportQueryPreHandler {

    @Autowired
    private IReportService iReportService;


    @Override
    public void preInternal(ReportQueryContext context) {
        Report report = context.getInnerParam(ReportQueryConstants.KEY_REPORT);
        List<QueryField> queryFields = iReportService.getQueryFields(report.getId());
        List<QueryField> innerFieldList = context.getInnerParam(ReportQueryConstants.KEY_INNER_FIELD_LIST);
        if(CollectionUtils.isNotEmpty(innerFieldList)){
            queryFields.addAll(innerFieldList);
        }
        context.putInnerParam(ReportQueryConstants.KEY_QUERY_FIELDS, queryFields);
    }

}
